var app = require("lzbjpk_app");
cc.Class({
	extends: require(app.subGameName + "_BaseForm"),

	properties: {
		prefab_posInfo: cc.Prefab,
		layer_allPlayer: cc.Node,
		node_title: cc.Node,
		node_roomInfo: cc.Node,
		wantime: cc.Node,

		sp_title: [cc.SpriteFrame],
	},
	OnCreateInit: function () {
		this.ComTool = app[app.subGameName + "_ComTool"]();
		this.RegEvent("NewVersion", this.Event_NewVersion, this);
	},
	Event_NewVersion: function () {
		this.isNewVersion = true;
	},
	OnShow: function (argDict) {
		console.log("UIBJPKDanJuOnShow", argDict);
		this.isNewVersion = false;
		app[app.subGameName + "_HotUpdateMgr"]().CheckUpdate(); //检测客户端是否有新版本
		this.PlayerName = [];
		let roomKey = app[app.subGameName.toUpperCase() + "Room"]().GetRoomProperty("key");
		this.ShareShortRoomID = roomKey;
		this.ShareLongRoomID = app[app.subGameName.toUpperCase() + "Room"]().GetRoomProperty("roomID");
		// let setEnd = argDict["setEnd"];
		// let posEndList = setEnd["posEndList"];
		let posEndList = argDict["recordPosInfosList"];
		let players = argDict["players"];
		let endTime = argDict["endSec"];
		let setId = argDict["setCnt"];
		let roomInfo = {
			roomKey: roomKey,
			endTime: endTime,
			setId: setId
		};

		let startTime = app[app.subGameName.toUpperCase() + "Room"]().GetRoomProperty("createSec");
		this.wantime.getComponent(cc.Label).string = "时长:" + this.ComTool.formatSeconds(endTime - startTime);
		this.ShowRoomInfo(roomInfo);
		this.layer_allPlayer.removeAllChildren();

		for (let i = 0; i < posEndList.length; i++) {
			let posEndInfo = posEndList[i];
			let posInfoNode = cc.instantiate(this.prefab_posInfo);
			let comp = posInfoNode.getComponent("playerdanju");
			comp.SetPosInfo(posEndInfo);
			this.layer_allPlayer.addChild(posInfoNode);
		}
		for (let j = 0; j < players.length; j++) {
			this.PlayerName.push(players[j]["name"]);
		}
	},
	ShowRoomInfo: function (roomInfo) {
		let lb_roomkey = this.node_roomInfo.getChildByName("lb_roomkey");
		let lb_setid = this.node_roomInfo.getChildByName("lb_setid");
		let lb_endtime = this.node_roomInfo.getChildByName("lb_endtime");
		this.GetLabelByNode(lb_roomkey).string = "房间号：" + roomInfo.roomKey;
		this.GetLabelByNode(lb_setid).string = "共" + roomInfo.setId + "局";
		this.GetLabelByNode(lb_endtime).string = app[app.subGameName + "_ComTool"]().GetDateYearMonthDayHourMinuteString(roomInfo.endTime);
	},

	OnClick: function (btnName) {
		if (btnName == "btn_exit") {
			/*let room = app[app.subGameName.toUpperCase()+"RoomMgr"]().GetEnterRoom();
			let needArg = app[app.subGameName.toUpperCase()+"RoomPosMgr"]().GetClientPos();
			let roomID = room.dataInfo.roomID;
			app[app.subGameName + "_GameManager"]().SendExitRoom(roomID, needArg);*/
			app[app.subGameName + "Client"].ExitGame();
		} else if (btnName == "btn_dissolve") {
			/*let BJPKRoomPosMgr = app[app.subGameName.toUpperCase()+"RoomPosMgr"]();
			let ClientPos = BJPKRoomPosMgr.GetClientPos();
			let player = BJPKRoomPosMgr.GetPlayerInfoByPos(ClientPos);
			if(!player)
				return;
			let posName = player.name;
			let roomID = app[app.subGameName.toUpperCase()+"RoomMgr"]().GetEnterRoomID();
			if(state == this.ShareDefine.RoomState_Playing){
				app[app.subGameName + "_GameManager"]().SendDissolveRoom(roomID, posName);
				return
			}*/
		} else if (btnName == "btn_continue") {
			if (this.isNewVersion == true) {
				app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("游戏有新版本更新，请返回大厅");
				return;
			}
			if (app[app.subGameName.toUpperCase() + "RoomMgr"]().clubId || app[app.subGameName.toUpperCase() + "RoomMgr"]().unionId) {
				let self = this;
				app[app.subGameName + "_NetManager"]().SendPack(app.subGameName + ".C" + app.subGameName.toUpperCase() + "ContinueEnterRoom", {}, function (event) {
					app[app.subGameName + "_NetManager"]().SendPack(this.ShareDefine.game_C1101GetRoomID, {});
					// self.CloseForm();
					self.CloseCurAllFrom();
				}, function (event) {
					if (event.Msg == "UNION_BACK_OFF_PLAYING") {
						app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("您已申请退赛，当前无法进行比赛，请取消退赛申请或联系赛事举办方");
					} else if (event.Msg == "UNION_APPLY_REMATCH_PLAYING") {
						app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("您的比赛分不足，已被淘汰，将被禁止参与赛事游戏，如要重新参与比赛，请联系举办方处理");
					} else if (event.Msg == "UNION_STATE_STOP") {
						app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("赛事已停用，无法加入房间，请联系赛事举办方");
					} else if (event.Msg == "ROOM_GAME_SERVER_CHANGE") {
						console.log("切换服务器");
					} else if (event.Code == 12) {
						console.log("游戏维护");
					} else if (event.Msg == "WarningSport_RoomJoinner") {
						app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("您所在的推广员队伍或上级队伍比赛分低于预警值，无法加入比赛，请联系管理");
					} else if (event.Msg == "CLUB_SPORT_POINT_WARN") {
						app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("您所在的亲友圈比赛分低于预警值，无法加入比赛，请联系管理");
					} else {
						app[app.subGameName + "_SysNotifyManager"]().ShowSysMsg("无法继续游戏，请联系赛事举办方");
					}
				});
				return;
			}
			//返回主界面
			app[app.subGameName + "Client"].ExitGame();
		} else if (btnName == "btn_share") {
			this.Click_btn_Share();
		} else if (btnName == "btn_mwshare") {
			this.Click_btn_MWShare();
		} else if (btnName == "btn_sharelink") {
			this.Click_btn_Sharelink();
		}
	},
	Click_btn_Share: function () {
		this.SDKManager.ShareScreen();
	},
	Click_btn_MWShare: function () {
		this.SDKManager.ShareScreenMW();
	},
	GetLabelByNode: function (node) {
		let label = node.getComponent(cc.Label);
		return label;
	},
});